package com.zan.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Zan
 * @Date 2023/10/17 13:16
 * @Description :
 */
public class WebUtils {

    /**
     * 将字符串渲染到客户端（浏览器），为了封装自定义的返回，能够返回自定义的ResponseResult Json格式的返回，并且保证响应是200
     * @param response 渲染对象
     * @param str 待渲染的字符串
     * @return
     */
    public static String renderString(HttpServletResponse response, String str) {
        try {
            response.setStatus(200);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
